HAL DMA2D initialization and configuration functions migration ¶
The goal of this page is to show how to migrate the initialization sequence using STM32CubeMX2:
Open STM32CubeMX2 DMA2D configuration panel.
Configure the HAL SW layer.
Configure the DMA2D advanced features.
Configure the NVIC if the application requires the DMA2D to be used in IT mode.
Generate the code.
HAL DMA2D configuration panel ¶
Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.
HAL DMA2D advanced features configuration ¶
Configure the advanced DMA2D features.
NVIC configuration ¶
Configure the NVIC in case of an interrupt.
Note
In HAL2, the transfer configuration is not part of the peripheral initialization. It should be done by the user according to the chosen transfer mode and to the application scenario.
Generated DMA2D initialization and de-initialization sequences ¶
The DMA2D initialization sequence is generated in the
mx_dma2d_init
function in the
mx_dma2d.c
file under
$YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.
Related concepts:
|
Topic |
HAL1 Code Snippet |
HAL2 Code Snippet |
|---|---|---|
|
Initialization and configuration sequence |
static void MX_DMA2D_Init(void)
{
hdma2d.Instance = DMA2D;
hdma2d.Init.Mode = DMA2D_M2M;
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB4444;
hdma2d.Init.OutputOffset = 0;
hdma2d.LayerCfg[1].InputOffset = 0;
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB4444;
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
hdma2d.LayerCfg[1].InputAlpha = 0xFF;
hdma2d.LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA;
hdma2d.LayerCfg[1].RedBlueSwap = DMA2D_RB_REGULAR;
hdma2d.LayerCfg[1].ChromaSubSampling = DMA2D_NO_CSS;
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
{
Error_Handler();
}
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
{
Error_Handler();
}
}
void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef* hdma2d)
{
if(hdma2d->Instance==DMA2D)
{
__HAL_RCC_DMA2D_CLK_ENABLE();
HAL_NVIC_SetPriority(DMA2D_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2D_IRQn);
}
}
|
hal_dma2d_handle_t *mx_dma2d_init(void)
{
if (HAL_DMA2D_Init(&hDMA2D, HAL_DMA2D) != HAL_OK)
{
return NULL;
}
HAL_RCC_DMA2D_EnableClock();
HAL_CORTEX_NVIC_SetPriority(DMA2D_IRQn, HAL_CORTEX_NVIC_PREEMP_PRIORITY_0,
HAL_CORTEX_NVIC_SUB_PRIORITY_0);
HAL_CORTEX_NVIC_EnableIRQ(DMA2D_IRQn);
return &hDMA2D;
}
|
|
Deinitialization sequence |
void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef* hdma2d)
{
if(hdma2d->Instance==DMA2D)
{
__HAL_RCC_DMA2D_FORCE_RESET();
__HAL_RCC_DMA2D_RELEASE_RESET();
__HAL_RCC_DMA2D_CLK_DISABLE();
HAL_NVIC_DisableIRQ(DMA2D_IRQn);
}
}
|
void mx_dma2d_deinit(void)
{
(void)HAL_DMA2D_DeInit(&hDMA2D);
HAL_RCC_DMA2D_DisableClock();
HAL_CORTEX_NVIC_DisableIRQ(DMA2D_IRQn);
}
|